package flc.ast.fragment;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.View;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import flc.ast.AppConfig;
import flc.ast.R;
import flc.ast.activity.AvatarActivity;
import flc.ast.activity.CollectActivity;
import flc.ast.activity.WallpaperActivity;
import flc.ast.databinding.FragmentLibraryBinding;
import stark.common.api.StkResApi;
import stark.common.base.IReqRetCallback;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.StatusBarUtils;
import stark.common.bean.StkTagResBean;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link LibraryFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class LibraryFragment extends BaseNoModelFragment<FragmentLibraryBinding> {

    private List<StkTagResBean> listAvatar = new ArrayList<>();
    private List<StkTagResBean> listWallpaper = new ArrayList<>();

    @Override
    protected int onCreate() {
        return R.layout.fragment_library;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.ivCollect.setOnClickListener(this);
        mDataBinding.ivAvatar1.setOnClickListener(this);
        mDataBinding.ivAvatar2.setOnClickListener(this);
        mDataBinding.ivAvatar3.setOnClickListener(this);
        mDataBinding.ivAvatar4.setOnClickListener(this);
        mDataBinding.ivAvatar5.setOnClickListener(this);
        mDataBinding.ivAvatar6.setOnClickListener(this);
        mDataBinding.ivWallpaper1.setOnClickListener(this);
        mDataBinding.ivWallpaper2.setOnClickListener(this);
        mDataBinding.ivWallpaper3.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivCollect://我的收藏
                startActivity(CollectActivity.class);
                break;
            case R.id.ivAvatar1://头像
                AvatarActivity.type = 0;
                AvatarActivity.hashId = listAvatar.get(0).getHashid();
                startActivity(AvatarActivity.class);
                break;
            case R.id.ivAvatar2:
                AvatarActivity.type = 1;
                AvatarActivity.hashId = listAvatar.get(1).getHashid();
                startActivity(AvatarActivity.class);
                break;
            case R.id.ivAvatar3:
                AvatarActivity.type = 2;
                AvatarActivity.hashId = listAvatar.get(2).getHashid();
                startActivity(AvatarActivity.class);
                break;
            case R.id.ivAvatar4:
                AvatarActivity.type = 3;
                AvatarActivity.hashId = listAvatar.get(3).getHashid();
                startActivity(AvatarActivity.class);
                break;
            case R.id.ivAvatar5:
                AvatarActivity.type = 4;
                AvatarActivity.hashId = listAvatar.get(4).getHashid();
                startActivity(AvatarActivity.class);
                break;
            case R.id.ivAvatar6:
                AvatarActivity.type = 5;
                AvatarActivity.hashId = listAvatar.get(5).getHashid();
                startActivity(AvatarActivity.class);
                break;
            case R.id.ivWallpaper1://壁纸
                WallpaperActivity.type = 0;
                WallpaperActivity.hashId = listWallpaper.get(0).getHashid();
                startActivity(WallpaperActivity.class);
                break;
            case R.id.ivWallpaper2:
                WallpaperActivity.type = 1;
                WallpaperActivity.hashId = listWallpaper.get(1).getHashid();
                startActivity(WallpaperActivity.class);
                break;
            case R.id.ivWallpaper3:
                WallpaperActivity.type = 2;
                WallpaperActivity.hashId = listWallpaper.get(2).getHashid();
                startActivity(WallpaperActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        Random random = new Random();
        mDataBinding.tvWallpaperNum1.setText(getString(R.string.wallpaper_num, random.nextInt(1000)));
        mDataBinding.tvWallpaperNum2.setText(getString(R.string.wallpaper_num, random.nextInt(1000)));
        mDataBinding.tvWallpaperNum3.setText(getString(R.string.wallpaper_num, random.nextInt(1000)));
        getAvatarData();
        getWallpaperData();
    }

    private void getAvatarData() {
        StkResApi.getChildTagList(null, AppConfig.AVATAR_DATA, StkResApi.createParamMap(0, 10), false, new IReqRetCallback<List<StkTagResBean>>() {
            @Override
            public void onResult(boolean success, String msg, @Nullable List<StkTagResBean> result) {
                if (success) {
                    if (result != null && result.size() > 0) {
                        listAvatar.addAll(result);
                    }
                }
            }
        });
    }

    private void getWallpaperData() {
        StkResApi.getChildTagList(null, AppConfig.WALLPAPER_DATA, StkResApi.createParamMap(0, 10), false, new IReqRetCallback<List<StkTagResBean>>() {
            @Override
            public void onResult(boolean success, String msg, @Nullable List<StkTagResBean> result) {
                if (success) {
                    if (result != null && result.size() > 0) {
                        listWallpaper.addAll(result);
                    }
                }
            }
        });
    }

}